package com.medical.medical.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.DateTimeException;
import java.util.Calendar;
import java.util.Date;

/**
 * @authorDesc 诸神在上，佑我程序，玄功护体，BUG皆去！
 * @author LiSuYang
 * @Date 2022-09-15 11:32:09
 * @version 1.0.0
 * @description 日期工具类
 */
public class DayOfweek {

    public String getDayOfweek(String dateTime){
        SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
        String[] weekDays={"星期日","星期一","星期二","星期三","星期四","星期五","星期六",};
        Calendar cal=Calendar.getInstance();
        Date date;
        try {
            date=format.parse(dateTime);
            cal.setTime(date);
        }catch (ParseException e){
            e.printStackTrace();
        }
        //一周的第几天
        int week=cal.get(Calendar.DAY_OF_WEEK)-1;
        /*if (week<0)
            week=0;
            return weekDays[week];*/
        if (week < 0){
            week = 0;
            return weekDays[week];
        }
        return weekDays[week];
    }

    /**
     * 患者查看医生排班比较
     * @param nowDate
     * @param workDate
     * @return
     */
    public static int workTime(String nowDate,String workDate){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date dt1 = df.parse(nowDate);
            Date dt2 = df.parse(workDate);
            if (dt1.getTime() > dt2.getTime()){
                return -1;
            }else if (dt1.getTime() < dt2.getTime()){
                return 1;
            }else {
                return 0;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }
}
